import { apiDecorateMange } from 'js/api'

export default {
  state: {
    channelList: [],
    par: {
      accessToken: '',
      threeMenuCode: '',
      currentPage: 1,
      terminal: '',
      showCount: 999
    }
  },
  getters: {
    channelList: state => state.channelList
  },
  actions: {
    /**
     * 获取 频道 列表
     */
    fetchChannelList({ state }, params) {
      state.par.accessToken = params.token
      state.par.terminal = params.terminal || ''
      state.par.threeMenuCode = params.three || ''

      apiDecorateMange.getChannelList(state.par).then(data => {
        const list = data.data.recordList || []
        state.channelList = list.map(val => {
          return {
            value: val.id,
            label: val.chName,
            iconPath: val.iconPath
          }
        })
        // state.channelList.unshift({value: '', label: '请选择'})
        if (params.three == 'videoList') {
          if (params.terminal == 'PC') {
            state.channelList.unshift({value: '0', label: 'PC首页'})
          } else if (params.terminal =='MOBILE') {
            state.channelList.unshift({value: '-1', label: 'APP首页'})
          }
        }
        if (!params.isShowClassify) {
          state.channelList = state.channelList.filter(item => {
            return item.label != '优选工厂' && item.label != '分类'
          })
        }
      })
    }
  }
}